var _o;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.State = undefined;
var c;
var $1$ResourceLoader = require("ResourceLoader");
var a = cc__importDefault($1$ResourceLoader);
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
(function (t) {
  t[t.Normal = 0] = "Normal";
  t[t.Selected = 1] = "Selected";
  t[t.Disabled = 2] = "Disabled";
})(c = exports.State || (exports.State = {}));
var def_CollectionItem = function (t) {
  function _ctor() {
    var e = null !== t && t.apply(this, arguments) || this;
    e.icon = null;
    e.bgSprite = null;
    e.indexLabel = null;
    e.stateNodes = [];
    e.bgSpriteFrames = [];
    e.disabledIconSpriteFrame = null;
    e.itemIndex = -1;
    e.state = c.Normal;
    return e;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.updateItem = function (t, e) {
    // 优化后的代码
    const context = this; // 使用更具描述性的变量名
    this.itemIndex = t; // 设置项索引
    this.state = e; // 设置项状态
    this.indexLabel.string = `No.${t}`; // 更新索引标签
    this.setState(e); // 更新状态

    // 根据状态处理图标
    if (e === c.Disabled) {
      this.icon.spriteFrame = this.disabledIconSpriteFrame; // 设置禁用图标
    } else {
      a.default.getInstance().load("Collection", `images/icons/${t}`, cc.SpriteFrame)
        .then(function (spriteFrame) {
          if (cc.isValid(context.node)) {
            context.icon.spriteFrame = spriteFrame; // 设置加载后的图标
          }
        });
    }
  };
  _ctor.prototype.setState = function (t) {
    // this.bgSprite.spriteFrame = this.bgSpriteFrames[t];
    // for (var e = 0; e < this.stateNodes.length; e++) {
    //   this.stateNodes[e].active = e === t;
    // }
    // 优化后的代码
    this.bgSprite.spriteFrame = this.bgSpriteFrames[t]; // 更新背景精灵帧

    // 更新状态节点的可见性
    this.stateNodes.forEach((node, index) => {
      node.active = index === t; // 仅激活与当前索引相同的节点
    });
  };
  _ctor.prototype.getItemIndex = function () {
    return this.itemIndex;
  };
  _ctor.prototype.getState = function () {
    return this.state;
  };
  cc__decorate([ccp_property(cc.Sprite)], _ctor.prototype, "icon", undefined);
  cc__decorate([ccp_property(cc.Sprite)], _ctor.prototype, "bgSprite", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "indexLabel", undefined);
  cc__decorate([ccp_property([cc.Node])], _ctor.prototype, "stateNodes", undefined);
  cc__decorate([ccp_property([cc.SpriteFrame])], _ctor.prototype, "bgSpriteFrames", undefined);
  cc__decorate([ccp_property(cc.SpriteFrame)], _ctor.prototype, "disabledIconSpriteFrame", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(cc.Component);
exports.default = def_CollectionItem;